/* eslint-disable eqeqeq */
import actionInfo from '../action'
import { partbAdd, partbQuery } from '../service/partbService'

function partbInfoReducer(state = { partbList: [] }, action) {
    switch (action.type) {
        case actionInfo.partb.ADD:
            return { partbList: [...state.partbList, action.payload] }
        case actionInfo.partb.QUERY:
            return { partbList: action.payload }
        default:
            return state
    }
}
export const asyncPartbQuery = (params) => async (dispatch) => {
    let { data } = await partbQuery(params);//做异步请求
    dispatch(partbInfoQuery(data.msg));//
}
const partbInfoQuery = (payload) => {
    return {
        type: actionInfo.partb.QUERY,
        payload
    }
}
export const asyncPartbAdd = (params) => async (dispatch) => {
    let { data } = await partbAdd(params);//做异步请求
    if (data.code == 1) {
        dispatch(partbInfoAdd(data.msg));
    }
}
const partbInfoAdd = (payload) => {
    return {
        type: actionInfo.partb.ADD,
        payload
    }
}
export default partbInfoReducer